var app = getApp();

Page({
    data: {
        navH: 0,
        opt_id: 0,
        type: 1,
        sort: 0,
        goodsList: [],
        page: 1,
        lastPage: !1,
        loading: !1,
        menuFixed: !1,
        appletKeyword: ""
    },
    toGoodsDetail: function(a) {
        console.log("asda", a);
        var t = a.currentTarget.dataset.goods_id;
        void 0 !== a.currentTarget.dataset.goods_sign && (t += "&goods_sign=" + a.currentTarget.dataset.goods_sign), 
        wx.navigateTo({
            url: "../goods/goods?goods_id=" + t
        });
    },
    sortGoods: function(a) {
        var t = a.currentTarget.dataset.type;
        1 == this.data.type && 1 == t || (a = this.data.type == t ? this.data.sort ? 0 : 1 : 3 == t && this.data.type != t ? 0 : 1, 
        this.setData({
            sort: a,
            type: t
        }), this.data.page = 1, this.data.lastPage = !1, (t = this).data.loading = !0, wx.pageScrollTo({
            scrollTop: t.data.menuTop - t.data.navH - t.data.plusH,
            duration: 0
        }), t.getGoodsList());
    },
    getMenuTop: function() {
        var t = this, a = wx.createSelectorQuery();
        a.select("#affix").boundingClientRect(), a.exec(function(a) {
            console.log(a, "top"), t.setData({
                menuTop: a[0].top
            });
        });
    },
    onPageScroll: function(a) {
        var t = this;
        a.scrollTop >= t.data.menuTop ? t.data.menuFixed || t.setData({
            menuFixed: !0
        }) : t.data.menuFixed && t.setData({
            menuFixed: !1
        });
    },
    navBack: function() {
        wx.navigateBack();
    },
    toIndex: function() {
        wx.switchTab({
            url: "../index/index"
        });
    },
    onLoad: function(a) {
        this.setData({
            navH: app.globalData.navHeight,
            appletKeyword: app.globalData.setting.appletKeyword
        }), console.log("options", a), void 0 !== a.opt_id && 0 != a.opt_id ? (this.data.opt_id = a.opt_id, 
        "undefined" != a.opt_name ? this.setData({
            opt_name: a.opt_name
        }) : this.setData({
            opt_name: "同类推荐"
        }), this.getMenuTop(), this.getGoodsList()) : wx.navigateBack();
    },
    getGoodsList: function(a) {
        var t = this;
        t.data.loading = !0, app.util.request({
            url: "entry/wxapp/getGoodsList",
            data: {
                page: t.data.page,
                type: t.data.type,
                sort: t.data.sort,
                opt_id: t.data.opt_id
            },
            success: function(a) {
                console.log(a), a.data.data.length < 1 ? t.data.lastPage = !0 : (t.data.goodsList = 1 == t.data.page ? a.data.data : t.data.goodsList.concat(a.data.data), 
                t.data.goods_id = a.data.data.goods_id, t.setData({
                    goodsList: t.data.goodsList,
                    goods_id: t.data.goods_id
                }), t.data.loading = !1);
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.data.page = 1, this.data.lastPage = !1, this.getGoodsList(function() {
            wx.stopPullDownRefresh();
        });
    },
    onReachBottom: function() {
        var a = this;
        !0 !== a.data.lastPage && !0 !== a.data.loading && (a.data.page++, a.getGoodsList());
    },
    onShareAppMessage: function() {
        var a = app.globalData.setting.share_title || "购物省钱，分享赚钱", t = app.globalData.setting.share_pic;
        return {
            title: a,
            path: "/first_duoduoke/pages/index/index" + (void 0 !== app.globalData.userInfo.uid ? "?from_uid=" + app.globalData.userInfo.uid + "&from_act=share" : ""),
            imageUrl: t,
            success: function(a) {
                "shareAppMessage:ok" == a.errMsg ? wx.showToast({
                    title: "分享成功",
                    icon: "success"
                }) : wx.showToast({
                    title: "分享失败",
                    icon: "none"
                });
            },
            fail: function(a) {
                "shareAppMessage:fail cancel" == a.errMsg || a.errMsg, wx.showToast({
                    title: "分享失败",
                    icon: "none"
                });
            }
        };
    }
});